package Boundry.GenericTools;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;

public abstract class MultiTabbedRequestTableList extends ViewDataPanel  {
	protected int numOfTabs;
	protected JTabbedPane mainTabbedPane;
	protected GenericTabel[] allRequestTableListPanels;
	protected String[] strArrAllRequestsTabsTitle;
	protected boolean[] toBuild;
	protected int startingIndex;
	
	public void setStartingIndex(int startingIndex) {
		this.startingIndex = startingIndex;
	}




	public	MultiTabbedRequestTableList(int numOfTabs) throws Exception
	{
        super();
        startingIndex=0;
		if (numOfTabs<=0)
	    {
	    	throw new Exception(); //TODO Ron: add specific exception
	    }
	    else
	    {
			this.numOfTabs = numOfTabs;
		    allRequestTableListPanels  = new GenericTabel[ this.numOfTabs];
		    System.out.println("To build initilzied");
		    toBuild = new boolean[this.numOfTabs];
		    strArrAllRequestsTabsTitle = new String[this.numOfTabs];
	    }
	}
	
	public void setWhatTobuild()
	{
		for (int i=0 ; i< this.numOfTabs ; i++)
				{
			       toBuild[i]=true;
				}
	}
	
    public boolean getTobuild(int i)
    {
    	return this.toBuild[i];
    }
    
    public void setTobuild(int i, boolean decition)
    {
    	 this.toBuild[i] = decition;
    }

	public GenericTabel[] getAllRequestTableListPanels() 
	{
		return allRequestTableListPanels;
	}
	
	public GenericTabel getRequestTableListPanel(int i) 
	{
		if (i>=0 && i< this.numOfTabs)
		{
		return allRequestTableListPanels[i];
		}
		return null;
	}

	public void setAllRequestTableListPanels(
			GenericTabel[] allRequestTableListPanels) {
		this.allRequestTableListPanels = allRequestTableListPanels;
	}

	public void buildPanel()
	{
		mainTabbedPane = new JTabbedPane(JTabbedPane.TOP);
		mainTabbedPane.setBounds(10, 38, 770, 341);
	    mainPanel.add(mainTabbedPane);
	    setValuesForAllRequestsUpperText();
	    setValuesForAllRequestsTabsTitle();
	    for(int i=0 ; i<numOfTabs ; i++)
	    {
	    	if (toBuild[i]) 
	    	{
	    	allRequestTableListPanels[i] = new GenericTabel(600, 200, "");
	    	mainTabbedPane.addTab(strArrAllRequestsTabsTitle[i], null, allRequestTableListPanels[i], null);
	    	}
	    	
	    }
	    System.out.println("focus on index " + startingIndex);
	    if (startingIndex>=0 && startingIndex < this.numOfTabs && toBuild[startingIndex])
	    {
	    	mainTabbedPane.setSelectedIndex(startingIndex);
	    }
	}

	public JTabbedPane getMainTabbedPane() {
		return mainTabbedPane;
	}
	public void setTitle(int i, String str)
	{
		if (i>=0 && i< this.numOfTabs)
		{
		strArrAllRequestsTabsTitle[i] = str ;
		}
	}

	public void hideTab(int tabToHide)
	{
		if (toBuild[tabToHide])
		{
		allRequestTableListPanels[tabToHide].setVisible(false);
		}
	}
	
	public void showTab(int tabToShow)
	{
		if (toBuild[tabToShow])
		{
			allRequestTableListPanels[tabToShow].setVisible(true);
		}
	}
	
	 public abstract void setValuesForAllRequestsTabsTitle();

	 public abstract void setValuesForAllRequestsUpperText();
	 
	 
	 
	 
	 
	 /*
	  * Shimon Adds
	  */
	 //first build the JTabbedPane
	 
	 public void buildTabPanel()
		{
			mainTabbedPane = new JTabbedPane(JTabbedPane.TOP);
			mainTabbedPane.setBounds(10, 38, 870, 341);
		    mainPanel.add(mainTabbedPane);
		    System.out.println("buildTabPanel() Ends");
		}
	 
	 	//Second build all tabs  
	 	
		public void buildTabI(int i,String tabName,String tableBorderName,String[] columnNames, String[][] tableData)
		{
			toBuild[i] = true;
			allRequestTableListPanels[i] = new GenericTabel(800, 250, tableBorderName);
			allRequestTableListPanels[i].buildTabel(columnNames, tableData);
			strArrAllRequestsTabsTitle[i] = tabName;
			mainTabbedPane.addTab(strArrAllRequestsTabsTitle[i], null, allRequestTableListPanels[i], null);
		}
		
		public int getChooseTab()
		{
			return mainTabbedPane.getSelectedIndex();
		}
	    public boolean isChosen() 
	    {
	    	return allRequestTableListPanels[getChooseTab()].isChosen();
	    }
	    
	    public int getChosen()
	    {
	    	return allRequestTableListPanels[getChooseTab()].getChosen();
	    }

}
